home *** CD-ROM | disk | FTP | other *** search
/ boe.pres.k12.wv.us / boe.pres.k12.wv.us.zip / boe.pres.k12.wv.us / Utilities / Xerox Workcentre 5335 / Windows Scan / 64-bit_x64 / Russian / cpsimage.cab / data / xipScripts / matchLift.elf < prev    next >
Text File  |  2009-04-23  |  5KB  |  169 lines

  1. /*
  2. ** Copyright(c) 2006 Xerox Corp. All Rights Reserved. Copyright protection
  3. ** claimed includes all forms and mattersof copyrightable material and
  4. ** information now allowed by statutory or judicial law or hereinafter granted,
  5. ** including without limitation, material generated from the software programs
  6. ** which are displayed on the screen such as icons, screen display looks, etc.
  7. */
  8.  
  9. #load "sys/stdlib.elf";
  10. #import "documentio.ucm";
  11. #import "ipcore2xip.ucm";
  12. #functions "ml2xip.ucm";
  13.  
  14. STRING USAGE = "\
  15.  Given two input document images (an original and an annotated copy), this\
  16.  script extracts the annotations present in the copy; repairs any broken\
  17.  strokes in the annotations; and outputs the difference image containing only\
  18.  the reconstructed annotations.  The default output format is PDF.\
  19.  Usage and import options are listed below:\n\n\
  20.  Usage: xipe mathcLift\
  21.            -im origfile:s orignal filename // required\
  22.                copyfile:s annotated copy filename // required\
  23.                 outfile:s outfilename // def: <copyfile>.ml.pdf\
  24.                  format:s output format // def: pdf\
  25.                    save:i save to disk // def: 1 (true)\
  26.                 display:i display output // def: 0 (false)\
  27.                   debug:i emit intermediate images // def: 0 (false)\n";
  28.  
  29.  
  30. IMPORT STRING  copyfile;
  31. IMPORT STRING  origfile;
  32. IMPORT STRING  outfile;
  33. IMPORT STRING  format  = "pdf";
  34. IMPORT INTEGER save    = 1;
  35. IMPORT INTEGER display = 0;
  36. IMPORT INTEGER debug   = 0;
  37.  
  38. XIPIMAGE imgOrig, imgCopy, imgDiff;
  39. FILE     file;
  40.  
  41. // Load image processing functions
  42. LoadClasses (filename: "xeng");
  43.  
  44. // Check for original filename
  45. if (!origfile) {
  46.    print "No original document filename specified";
  47.    print USAGE;
  48.    end;
  49.    }
  50.  
  51. // Check if original file exists
  52. file = new (FILE, path: origfile);
  53. if (!file.exists ()) {
  54.    print "Original document file does not exist";
  55.    print USAGE;
  56.    end;
  57.    }
  58.  
  59. // Check if original filename specifies a file
  60. if (!file.isFile ()) {
  61.    print "Original document file is a directory";
  62.    print USAGE;
  63.    end;
  64.    }
  65.  
  66. // Check for annotated copy filename
  67. if (!copyfile) {
  68.    print "No annotated copy document filename specified";
  69.    print USAGE;
  70.    end;
  71.    }
  72.  
  73. // Check if annotated copy file exists
  74. file = new (FILE, path: copyfile);
  75. if (!file.exists ()) {
  76.    print "Annotated copy document file does not exist";
  77.    print USAGE;
  78.    end;
  79.    }
  80.  
  81. // Check if annotated copy filename specifies a file
  82. if (!file.isFile ()) {
  83.    print "Annotated copy document file is a directory";
  84.    print USAGE;
  85.    end;
  86.    }
  87.  
  88. // Read original document image
  89. imgOrig = readimage (filename: origfile).exec ();
  90.  
  91. // Read copy image
  92. imgCopy = readimage (filename: copyfile).exec ();
  93.  
  94. // Adjust dimension of document images accordingly
  95. // Note: This is a temporary fix for making certain the document images can be
  96. // aligned in the document matching phase. A better solution needs to be
  97. // implemented (most likely embedded in the MatchLift function) for handling
  98. // the alignment issue.
  99. DOUBLE w_orig  = imgOrig.imageWidth;
  100. DOUBLE h_orig  = imgOrig.imageHeight;
  101. DOUBLE w_copy  = imgCopy.imageWidth;
  102. DOUBLE h_copy  = imgCopy.imageHeight;
  103. DOUBLE sx_orig = 1.0;
  104. DOUBLE sy_orig = 1.0;
  105. DOUBLE sx_copy = 1.0;
  106. DOUBLE sy_copy = 1.0;
  107. INTEGER r;
  108.  
  109. if (w_copy > w_orig) {
  110.    r = w_copy / w_orig;
  111.    if (r > 1)
  112.       sx_copy = w_orig / w_copy;
  113.    }
  114. else {
  115.    r = w_orig / w_copy;
  116.    if (r > 1)
  117.       sx_orig = w_copy / w_orig;
  118.    }
  119.  
  120. if (h_copy > h_orig) {
  121.    r = h_copy / h_orig;
  122.    if (r > 1)
  123.       sy_copy = h_orig / h_copy;
  124.    }
  125. else {
  126.    r = h_orig / h_copy;
  127.    if (r > 1)
  128.       sy_orig = h_copy / h_orig;
  129.    }
  130.  
  131. if (sx_orig != 1.0 || sy_orig != 1.0)
  132.    imgOrig = imgOrig.scale (afactor: (sx_orig, sy_orig), bicubic: 1);
  133.  
  134. if (sx_copy != 1.0 || sy_copy != 1.0)
  135.    imgCopy = imgCopy.scale (afactor: (sx_copy, sy_copy), bicubic: 1);
  136.  
  137. // Make certain original image is 1-bit gray
  138. if (imgOrig.getMember (member: "photometry") != XIP_GRAY_COLOR)
  139.    imgOrig = imgOrig.cspace (outspace: "gray");
  140.  
  141. if (imgOrig.getMember (member: "bits") != 1)
  142.    imgOrig = imgOrig.convert (to: (1));
  143.  
  144. // Make certain copy image is 8-bit gray
  145. if (imgCopy.getMember (member: "photometry") != XIP_GRAY_COLOR)
  146.    imgCopy = imgCopy.cspace (outspace: "gray");
  147.  
  148. if (imgCopy.getMember (member: "bits") != 8)
  149.    imgCopy = imgCopy.convert (to: (8));
  150.  
  151. // Get difference image of original and copy images
  152. imgDiff = MatchLift (orig: imgOrig, copy: imgCopy, debug: debug);
  153.  
  154. print "Total Excution Time For Script: " + TimeCheck ();
  155.  
  156. // Display difference image if display is TRUE
  157. if (display)
  158.    imgDiff.display (advanced: "spd -buffer");
  159.  
  160. // Save difference image if save is TRUE
  161. if (save) {
  162.   DOCUMENTWRITER dw;
  163.   if (!outfile)
  164.      outfile = copyfile.name () + "-annlift." + format;
  165.   dw = CreateDocumentWriter (filename: outfile);
  166.   dw.appendPage (pgImg: imgDiff);
  167.   dw.release ();
  168.   }
  169.